import  axios from  'axios'

export default class SystemRoleService {
    static systemRoleService = null

    static getInstance(){
        if(this.systemRoleService == null){
            this.systemRoleService = new SystemRoleService()
        }
        return this.systemRoleService
    }

    //查询所有角色
    list(role){
        return axios.get('http://localhost/roles',{
            params:role
        })
    }

    list2(){
        return axios.get(`http://localhost/roles/list2`)
    }

    //根据用户id查找用户角色
    getRoleByUserId(id){
        return axios.get(`http://localhost/roles/${id}`)
    }

    getUserByUserId(id){
        return axios.get(`http://localhost/users/${id}`)
    }

    init(id){
        return axios.all([this.list2(),this.getRoleByUserId(id),this.getUserByUserId(id)])
    }

    save(id,id2){
        var a ={}
        a.Myid=id;
        a.id=id2.toString()
        return axios.post(`http://localhost/systemuserroles`,a)
    }

    remove(id,id2){
        var a ={}
        a.Myid=id;
        a.id=id2.toString()
        return axios.delete(`http://localhost/systemuserroles`,{
            params:a
        })
    }

    updatestatus(id,status){
        var a ={}
        a.id=id;
        a.status=status
        return axios.put(`http://localhost/users`,a)
    }

    del(id){
        return axios.delete(`http://localhost/roles/${id}`)
    }

}
